package zdream.pmfield.stage.buff.foe;

import zdream.pmfield.data.foe.MoveTemplate;
import zdream.pmfield.stage.director.AttackContext;
import zdream.pmfield.stage.object.StageMove;

/**
 * @author Zdream
 * @date 2023-12-19
 * @since 0.0.1
 */
public class ChargingMoveExecutingBuff extends MoveExecutingBuff {
	public final StageMove chargingSubMove;
	public final StageMove releaseSubMove;

	public ChargingMoveExecutingBuff(StageMove rawMove) {
		super(findParentMove(rawMove));
		chargingSubMove = move.findSubMove(MoveTemplate.SUB_TITLE_CHARGING);
		releaseSubMove = move.findSubMove(MoveTemplate.SUB_TITLE_RELEASE);
	}

	private static StageMove findParentMove(StageMove move) {
		if (move.parent != null) {
			return move.parent;
		}
		return move;
	}

	@Override
	public void init() {
		super.init();
		putChargingMoveToContext();
	}

	private void putChargingMoveToContext() {
		AttackContext context = target.stage.director.getCurrentAttackContext();

		// 第一次执行的时候, 默认放到 context.currentMove 里面的是 parentMove, 这里会修改为 chargingSubMove
		// 等到真正释放的时候, 会直接使用 releaseSubMove, 这里就不用改了
		if (context.currentMove == move) {
			context.currentMove = chargingSubMove;
		}
	}
}
